package controller

import (
	"hft/Http/Models/request"
	services "hft/Http/Services"
	utils "hft/Http/Utils"
	"hft/tools"
	"strconv"

	"github.com/gin-gonic/gin"
)

type BrokerHelp struct{}

func (*BrokerHelp) GetLouPanList(c *gin.Context) {
	var data request.BrokerHelpPage

	c.ShouldBind(&data)

	claims, err := tools.GetClaims(c)

	if err != nil {
		utils.FailWithMessage("授权失败", c)
		return
	}

	res, err := services.BrokerHelpServices.GetLouPanList(&data, claims.BaseClaims)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(res, c)

}

func (*BrokerHelp) GetLouPanInfo(c *gin.Context) {
	id, _ := strconv.Atoi(c.DefaultQuery("id", "0"))

	claims, err := tools.GetClaims(c)

	if err != nil {
		utils.FailWithMessage("授权失败", c)
		return
	}

	data, err := services.BrokerHelpServices.GetLouPanInfo(id, claims.BaseClaims)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(data, c)
}

var BrokerHelpController = new(BrokerHelp)
